/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_ora_mar_skip.c                                   */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/18 by jikw                                 */
/*******************************************************************/

#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frbyte_buffer.h"

#include "../../../../src/module/oracle/config.h"
#include <oracle/ora_core.h>
#include <oracle/ttc/ora_mar_engine.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

int ora_mar_skip(L7_ora_packet *p_st_ora_packet, unsigned long long ull_need_len);

static void __case1(void)
{
    int i_ret = 0;
    long ull_need_len = 0;
    L7_ora_packet *p_st_ora_packet = NULL;

    i_ret = ora_mar_skip(p_st_ora_packet, ull_need_len);

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
}

static void __case2(void)
{
    int i_ret = 0;
    L7_ora_packet *p_st_ora_packet = NULL;

    p_st_ora_packet = (L7_ora_packet *)frmalloc(sizeof(L7_ora_packet));
    memset(p_st_ora_packet, 0x00, sizeof(L7_ora_packet));
    p_st_ora_packet->p_st_packet = bytebuff_creat();
    bytebuff_add(p_st_ora_packet->p_st_packet, (char *)"abc", strlen("abc"));

    i_ret = ora_mar_skip(p_st_ora_packet, strlen("abc"));

    CU_ASSERT_EQUAL(i_ret, FR_SUCC);
    bytebuff_free(&p_st_ora_packet->p_st_packet);
    frfree(p_st_ora_packet);
}

static void __case3(void)
{
    int i_ret = 0;
    L7_ora_packet *p_st_ora_packet = NULL;

    p_st_ora_packet = (L7_ora_packet *)frmalloc(sizeof(L7_ora_packet));
    memset(p_st_ora_packet, 0x00, sizeof(L7_ora_packet));
    p_st_ora_packet->p_st_packet = bytebuff_creat();
    bytebuff_add(p_st_ora_packet->p_st_packet, (char *)"abc", strlen("abc"));

    i_ret = ora_mar_skip(p_st_ora_packet, strlen("abc")+1);

    CU_ASSERT_EQUAL(i_ret, FR_FAIL);
    bytebuff_free(&p_st_ora_packet->p_st_packet);
    frfree(p_st_ora_packet);
}

int add_suite_ora_mar_skip(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" ora_mar_skip()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
